package br.unicamp.ic.sgct.client.aplicacao.trabalho;



import br.unicamp.ic.sgct.client.SisGesConfTec;
import br.unicamp.ic.sgct.client.aplicacao.comum.BaseListenerImpl;
import br.unicamp.ic.sgct.client.apresentacao.widgets.MensagemUI;
import br.unicamp.ic.sgct.client.dominio.to.TrabalhoTO;


import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

public class TrabalhoListenerImpl extends BaseListenerImpl implements TrabalhoListener {

    
    private TrabalhoServiceAsync service;

    public TrabalhoListenerImpl(MensagemUI msgWidget) {
        super(msgWidget);

        getService();
    }

    /**
     *
     * @return SubmissaoServiceAsync
     */
    public TrabalhoServiceAsync getService() {
        if (service == null) {
            service = GWT.create(TrabalhoService.class);
            ServiceDefTarget target = (ServiceDefTarget) service;
            target.setServiceEntryPoint(SisGesConfTec.instance().getModuleRelativeURL() + TrabalhoService._RELATIVE_PATH);
        }
        return service;
    }

    /**
     *
     * @param to
     * @param handler
     */
    @Override
    public void submeterTrabalho(TrabalhoTO to, final HandlerSubmeterTrabalho handler) {

        getService().submeterTrabalho(to, new AsyncCallback<TrabalhoTO>() {

            @Override
            public void onSuccess(TrabalhoTO result) {
                handler.handleSucesso(result);
            }

            @Override
            public void onFailure(Throwable caught) {
                handler.handleErro(caught);
            }
        });
    }  
}